package com.example.education.Controller;


import com.example.education.Bean.RecommendInfo;
import com.example.education.Bean.StudentInfo;
import com.example.education.Mapper.StudentInfoMapper;
import com.example.education.service.impl.StudentInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚
 * @since 2023-03-27
 */
@RestController
@RequestMapping("/student")
@CrossOrigin
public class StudentInfoController {

    @Autowired
    private StudentInfoMapper studentInfoMapper;
    @Autowired
    private StudentInfoServiceImpl studentInfoService;

    //    @PostMapping("/login")
//    public Integer save(@RequestBody(required = false) StudentInfo studentInfo){//将传回来的json对象转
//        System.out.println(studentInfo);
//        return studentInfoMapper.insert(studentInfo);
//    }
    //注册
    @PostMapping("/register")
    public Integer register(@RequestBody(required = false) StudentInfo studentInfo) {
        System.out.println(studentInfo);
        return studentInfoService.register(studentInfo);
    }

    //登录
    @PostMapping("/login")
    public Integer login(@RequestBody(required = false) StudentInfo studentInfo) {
        System.out.println(studentInfo);
        return studentInfoService.login(studentInfo);
    }


    @PostMapping("/recommend")
    //如果这个参数是非必填参数的话，我们应该设置该参数的required属性为false: @RequestParam(required = false)
    public StudentInfo recommend(@RequestBody(required = false) RecommendInfo recommendInfo) {
        //将前端传回来的学生的uid查到该学生的信息
        StudentInfo studentInfo = studentInfoService.select(recommendInfo.getUid());

        System.out.println(recommendInfo);
        studentInfoService.grade(studentInfo, recommendInfo);

        return studentInfo;
    }


    @GetMapping("/find")
    public int find() {
        int id = 1;
        return id;
    }


}

